package vfs.persist.association.impl;

import java.sql.Connection;
import vfs.persist.entity.build.impl.VFSGroupBuilder;
import vfs.persist.entity.build.impl.VFSUserBuilder;
import vfs.obj.entity.VFSUser;
import vfs.obj.entity.VFSGroup;
import vfs.filter.VFSFilter;
import vfs.persist.association.VFSUserToGroupManager;
import java.util.Iterator;

/**
 *
 * @author Matthew Eavenson <durandal@uga.edu>
 */
public class VFSUserToGroupManagerImpl implements VFSUserToGroupManager{
    
    private VFSAssociationManagerImpl<VFSUser, VFSGroup> am;
    
    public VFSUserToGroupManagerImpl(Connection conn){
        am = new VFSAssociationManagerImpl<VFSUser, VFSGroup>(conn, new VFSUserBuilder(), 
                                                 new VFSGroupBuilder(), 
                                        "vfsUserToGroup", "vfsuser", "vfsgroup");
    }
    
    @Override
    public Iterator<VFSUser> getUsers(VFSGroup group, VFSFilter filter){
        return am.findTMM(group, filter);
    }
    
    @Override
    public Iterator<VFSGroup> getGroups(VFSUser user, VFSFilter filter){
        return am.findUMM(user, filter);
    }
    
    @Override
    public void addUserToGroup(VFSUser user, VFSGroup group){
        am.persistMM(user, group);
    }
    
    @Override
    public void removeUserFromGroup(VFSUser user, VFSGroup group){
        am.removeMM(user, group);
    }
    
}
